import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
      },
      {
        path: 'password',
        component: () => import('@/views/password.vue'),
        hidden: true
      }
    ]
  },


  {
    path: '/contentSet',
    component: Layout,
    redirect: '/contentSet/list',
    name: '校园墙内容管理',
    meta: { title: '贴子管理', icon: 'el-icon-chat-line-square' },
    children: [
      {
        path: 'list',
        name: '内容管理',
        component: () => import('@/views/contentSet/list'),
        meta: { title: '内容管理', icon: 'info' }
      },
      {
        path: 'add',
        name: '内容添加',
        component: () => import('@/views/contentSet/add'),
        meta: { title: '内容添加', icon: 'el-icon-circle-plus-outline' }
      },
      {
        path: 'edit/:cid',
        name: '编辑',
        component: () => import('@/views/contentSet/edit'),
        meta: { title: '编辑', noCache: true },
        hidden: true
      }
    ]
  },
  {
    path: '/commentSet',
    component: Layout,
    redirect: '/commentSet/list',
    name: '评论管理',
    meta: { title: '评论管理', icon: 'el-icon-chat-line-round' },
    children: [
      {
        path: 'list',
        name: '全部评论',
        component: () => import('@/views/commentSet/list'),
        meta: { title: '全部评论', icon: 'comment' }
      },
      {
        path: 'report',
        name: '举报管理',
        component: () => import('@/views/commentSet/report'),
        meta: { title: '举报管理', icon: 'el-icon-warning-outline' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

/**
 * 动态路由
 */
export const asyncRoutes = [

  {
    path: '/config',
    component: Layout,
    redirect: '/config/list',
    name: '系统管理',
    meta: { title: '系统管理', icon: 'el-icon-setting', roles: ['ROLE_superAdmin'] },
    children: [
      {
        path: 'list',
        name: '参数配置',
        component: () => import('@/views/configSet/list'),
        meta: { title: '参数配置', icon: 'el-icon-notebook-1', roles: ['ROLE_superAdmin'] }
      },

      {
        path: 'dict',
        name: '字典管理',
        component: () => import('@/views/dictSet/list'),
        meta: { title: '字典管理', icon: 'el-icon-notebook-2', roles: ['ROLE_superAdmin'] }
      }
    ]
  },
  {
    path: '/userSet',
    component: Layout,
    redirect: '/userSet/list',
    name: '用户管理',
    meta: { title: '用户管理', icon: 'el-icon-user' , roles: ['ROLE_superAdmin']},
    children: [
      {
        path: 'list',
        name: '用户管理',
        component: () => import('@/views/userset/list'),
        meta: { title: '用户管理', icon: 'user' , roles: ['ROLE_superAdmin']}
      },
      {
        path: 'add',
        name: '用户添加',
        component: () => import('@/views/userset/add'),
        meta: { title: '用户添加', icon: 'el-icon-circle-plus-outline' , roles: ['ROLE_superAdmin']}
      },
      {
        path: 'edit/:id',
        name: '编辑',
        component: () => import('@/views/userset/add'),
        meta: { title: '编辑', noCache: true , roles: ['ROLE_superAdmin']},
        hidden: true
      }
    ]
  },
  {
    path: '/metaSet',
    component: Layout,
    redirect: '/metaSet/list',
    name: '分类管理',
    meta: { title: '分类管理', icon: 'meta' , roles: ['ROLE_superAdmin']},
    children: [
      {
        path: 'list',
        name: '分类管理',
        component: () => import('@/views/metaSet/list'),
        meta: { title: '分类管理', icon: 'meta' , roles: ['ROLE_superAdmin']}
      },
      {
        path: 'add',
        name: '分类添加',
        component: () => import('@/views/metaSet/add'),
        meta: { title: '分类添加', icon: 'el-icon-circle-plus-outline' , roles: ['ROLE_superAdmin']}
      },
      {
        path: 'edit/:id',
        name: '编辑',
        component: () => import('@/views/metaSet/add'),
        meta: { title: '编辑', noCache: true , roles: ['ROLE_superAdmin']},
        hidden: true
      }
    ]
  },

  // 404 页面必须放置在最后一个页面
  { path: '*', redirect: '/404', hidden: true }

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
